package net.zjitc.controller;

import net.zjitc.domain.User;
import net.zjitc.service.UserService;
import net.zjitc.service.impl.UserServiceImpl;
import net.zjitc.utils.URLMapping;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 2 * @Author: 洪瑶
 * 3 * @Date: 2018/11/23 9:07
 * 4
 */
public class registController {

    @URLMapping(url = "/registUI")
    public String registUI(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return "/WEB-INF/user/regist.jsp";
    }

    @URLMapping(url = "/regist")
    public void regist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = new User();
        try {
            BeanUtils.populate(user,request.getParameterMap());

        } catch (Exception e) {
            e.printStackTrace();
        }

        UserService service = new UserServiceImpl();
        try {
            service.sqlregister(user);
        } catch (SQLException e) {
            e.printStackTrace();
            return ;
        }
        response.sendRedirect("");
    }


    @URLMapping(url = "/user_registPage")
    public String user_registPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        return "/WEB-INF/user/regist.jsp";
    }
}
